<?php
namespace app\common\model;

use think\Model;

class Goods extends Model
{
    /**
     * @param $where
     * @param string $field
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function findInfo($where, $field='') {
        return $this->where($where)->field($field)->find();
    }

    /**
     * @param bool $where
     * @param string $order
     * @param string $field
     * @param bool $limit
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function selectList($where=false, $order='', $field='', $limit=false) {
        
        return $this->where($where)->order($order)->field($field)->limit($limit)->select();
    }

    /**
     * @param array $where
     * @param bool $pageSize
     * @param array $pageconfig
     * @param bool $fields
     * @param string $order
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function pageList(array $where=[], $pageSize=false, array $pageconfig=[], $fields=false, $order='id desc')
    {
        return $this->where($where)->field($fields)->order($order)->paginate($pageSize, false, $pageconfig);
    }

    /**
     * @param array $where
     * @param bool $pageSize
     * @param array $pageconfig
     * @param bool $fields
     * @param string $order
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function pageListJoinCate(array $where=[], $pageSize=false, array $pageconfig=[], $fields=false, $order='g.id desc')
    {
        return $this->alias('g')->join('__GOODS_CATE__ gc', 'gc.id=g.cate_id')->where($where)->field($fields)->order($order)->paginate($pageSize, false, $pageconfig);
    }
}